<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="java.util.Iterator"%>
<%@page import="net.groupme.model.ObjectFactory"%>
<%@page import="org.groupme.contextsearch.evaluation.ContextBasedSearchEvaluation"%>
<%@page import="org.groupme.contextsearch.ContextSearch"%>
<%@page import="java.util.List"%>
<%@page import="net.groupme.search.strategy.model.WeightedUser"%>
<%@page import="org.groupme.contextsearch.evaluation.model.UserEvaluation"%>
<%@page import="net.groupme.model.Tag"%>
<%@page import="org.groupme.contextsearch.evaluation.model.SearchSetting"%>
<%@page import="org.groupme.contextsearch.model.SearchContextType"%>
<%@page import="org.groupme.contextsearch.evaluation.io.ReadWriteDBUtility"%>
<%@page import="org.groupme.contextsearch.SearchContextFactory"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page import="net.groupme.search.strategy.model.WeightedTag"%>
<%@page import="net.groupme.search.strategy.model.WeightedResource"%>
<%@page import="org.groupme.contextsearch.evaluation.ParticipantIncentives"%>
<%@page import="java.util.ArrayList"%>
<%@page import="net.groupme.model.User"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<!-- meta tags, link to css:  -->
	<%@ include file="../jsp-includes/mymetaheader.jsp" %>
	
	<!--  Ajax-Includes -->
    <script type='text/javascript' src='/GroupMe/dwr/interface/DWRUserManager.js'></script>
    <script type='text/javascript' src='/GroupMe/dwr/interface/DWRContextSearchEvaluationManager.js'></script>
    <script type='text/javascript' src='/GroupMe/dwr/engine.js'></script>
    <script type='text/javascript' src='/GroupMe/dwr/util.js'></script>
    <script type="text/javascript" src="<%= request.getContextPath()%>/highslide/highslide.js"></script>
	
	<!-- Prototype-Include -->
	<script src="<%= request.getContextPath()%>/scriptaculous/prototype.js" type="text/javascript"></script>
	<script src="<%= request.getContextPath()%>/scriptaculous/scriptaculous.js" type="text/javascript"></script>

	
	<script type="text/javascript">   
	    hs.graphicsDir = '<%= request.getContextPath()%>/highslide/graphics/';
	    hs.outlineType = 'rounded-white';
	    hs.outlineWhileAnimating = true;
	    hs.allowMultipleInstances = false;
	    hs.marginRight = 50;
	    
	    
	    function preview(website) {
		return hs.htmlExpand(this, { src: website, contentId: 'htmlPrev', objectType: 'iframe'});
		}
	</script>
	
	<title>Welcome to GroupMe! - The Social Semantic Web</title>
	
	<!-- setting initial tag-cloud height -->
	<script type="text/javascript">
	/*This funtion sets the height of the tag-cloud to the (almost) same size as the group-list*/
		function setTagCloudSize(){
			var groupListHeight = $('main_home').getHeight();
			var userListHeight = $('latestUsers').getHeight();
			var tagCloudHeightSize = groupListHeight - userListHeight;
			var tagCloudHeight = tagCloudHeightSize + "px";
			$('tagCloud_content').setStyle({
				height: tagCloudHeight,
			});
		}
		
		
		function showCompleteTagCloud(){
			DWRSearchManager.getCompleteTagCloud(showCompleteTagCloudCallback);
			$('main_home_content').hide();
			$('user_groups').setStyle({paddingBottom: '9px'});
			$('completeTagcloud_content').show();
			$('completeTagcloud_content').innerHTML += "<img src=\"<%= request.getContextPath() + RENDERING_CONSTANTS.RELATIVE_PATH_OF_AJAX_LOADING_IMAGE %>\"/> " +
					"<small><i>Computing the tag cloud.</i></small>";
		}
		
		/**
		 * Visualize the complete groupme tag cloud.
		 */
		 function showCompleteTagCloudCallback(tagCloud){
		 	if(tagCloud == null || tagCloud.html == ""){
		 		$('completeTagcloud_content').innerHTML = "<i>Sorry, there is a problem with computing the tag cloud. Try it again</i>";
		 	}else{
		 		$('completeTagcloud_content').innerHTML = tagCloud.html;
		 		$('completeTagcloud_content').show();
				}
			}
		<% if(userManager.getUser() != null){ 	
		    String idOfParticipant = request.getParameter("userid"); 
			if(idOfParticipant == null || "".equals(idOfParticipant)){
				idOfParticipant = userManager.getUser().getId();
			}	
			%>
		/**
		 * The participant rated a user: Store the rating.
		 */		
		function storeUserRating(userId, rating, setting){
			DWRContextSearchEvaluationManager.storeUserRating('<%= idOfParticipant %>', userId, rating, setting, stored);
		}
		/**
		 * The participant rated a tag: Store the rating.
		 */		
		function storeTagRating(tagId, rating, setting){
			DWRContextSearchEvaluationManager.storeTagRating('<%= idOfParticipant %>', tagId, rating, setting, stored);
		}
		/**
		 * The participant rated a resource: Store the rating.
		 */		
		function storeResourceRating(resourceId, rating, setting){
			DWRContextSearchEvaluationManager.storeResourceRating('<%= idOfParticipant %>', resourceId, rating, setting, stored);
		}	
		
		function stored(resultMessage){
			$('incentive-score').innerHTML = "" + resultMessage + " beers";
		}
		<% }%>	
		//init stuff:		
	function init() {
		DWRUtil.useLoadingMessage();
		computeTagCloud();  
	}
	</script>
	
	<style type="text/css" media="screen">
				
			/* put the left rounded edge on the track */
			.slider-track-left {
				position: absolute;
				width: 5px;
				height: 9px;
				background: transparent url(./images/slider-images-track-left.png) no-repeat top left;
			}
			
			/* put the track and the right rounded edge on the track */
			.slider-track {
				background: transparent url(./images/slider-images-track-right.png) no-repeat top right;
			}
			
			td {
				padding: 4px;
				margin: 4px;
				vertical-align: top;
				
				border: thin;
				border-style: dotted;
				border-color: gray;
			}
		</style>
	
</head>
<body onload="init();">
<% if(userManager.getUser() != null){ %>
	<div id="incentives" style="float:left; position: fixed; top: 120px; left: 20px;">
		<small>
			<table style="border: thin; border-style: solid; border-color: gray; filter:alpha(opacity=80); opacity: 0.8;">
				<tr><td><i><strong>meta</strong></i></td></tr>
				<tr><td>You earned: <span id="incentive-score"><%= ParticipantIncentives.getScore(userManager.getUser()) %> beers</span></td></tr>
				<tr><td>
					<p>Select a query:</p>
					<form action="./study.jsp" method="get">
						<select name="tagid">
					<% 	for(Tag tag: ContextBasedSearchEvaluation.tagsAsList){%>
							<option value="<%=tag.getId() %>"><%= tag.getKeyword() %></option>
						<%}%>
						</select>
						<button type="submit">go</button>
					</form>
					
					<br/>
					<%	List<Tag> personalList = ContextBasedSearchEvaluation.getTagsForParticipant(userManager.getUser());
						if(!personalList.isEmpty()){%>
						Queries especially assigned <br/>to you: 
						<%for(Tag tag: personalList){ %>
						<br/>- <a href="./study.jsp?tagid=<%= tag.getId() %>"><%=tag.getKeyword() %></a>
					<%	  }
						}
					%>
				</td></tr>
				<tr><td>Getting started:<br/>
				- <a href="<%= VIEW_VOCABULARY.GROUPME_BASE_URL + "contextsearch/" %>">how to</a><br/>
				- <a href="http://groupme.org/videos/study-german.swf">video</a> (german)</td></tr>
			</table>
		</small>
	</div>
	<%} %>
	<!-- title image, logo:  -->
	<div id="groupme_header">
		<%@ include file="../jsp-includes/groupme_header.jsp" %>
	</div>
	
	<!-- Menu: -->
	<div id="menu">
		<%@ include file="../jsp-includes/groupme_menu.jsp" %>
	</div>
	<!-- content and sidebar -->
	<!-- Content: -->
	<div id="mycontent">
		<div id="welcome" style="text-align: center;  margin-bottom: 1em; color: #ccc;  font-size: small;">
				Welcome to the GroupMe! Context Search User Study 
		</div>
		<div id="main_home" style="font-size: small">
		
			<% if(userManager.getUser() == null){ %>
				Please login with your GroupMe! user account. 
			<%} else { %>
			<%
			String idOfParticipant = request.getParameter("userid"); 
			if(idOfParticipant == null || "".equals(idOfParticipant)){
				idOfParticipant = userManager.getUser().getId();
			}	
			
			int rowCounter = 0;
			int ratingCounter = 0;
			//for(Tag queryTag: ContextBasedSearchEvaluation.searchSettings.keySet()){ 

			Tag  dummyTag = ObjectFactory.getTagById(request.getParameter("tagid"));
			Tag  queryTag = ObjectFactory.getInMemoryTag(dummyTag.getKeyword()); 
			//TODO: equals-Methiode von Tag ueberpruefen!
			for(Tag theTag: ContextBasedSearchEvaluation.searchSettings.keySet()){
				if(dummyTag.getId().equals(theTag.getId())){
					queryTag = theTag;
				}
			} %>
				
				<h1>Query: <%= queryTag.getKeyword() %></h1>
				<br/><br/>
				
				<!-- RESOURCE -->
				
				<br/><br/>
				<h2>Resources:</h2>
				<br/><br/>
				
				<% List<WeightedResource> resultResources = ContextBasedSearchEvaluation.getAccumulatedResourceList(queryTag);
				rowCounter=0;
				int idOfSearchSettingWithoutContext = -1;
				   %>					
					<table style="border: thin; border-style: solid; border-color: gray;">
					<tr>
						<td><strong>resource </strong><span style="font-size: x-small;color: gray;">ordered by label</span></td>
						<td><strong>click to show preview </strong></td>
						<td><strong>relevant to query? </strong><br/>query: <a href="<%= queryTag.getURI() %>" target="previewBrowserWindow"><%= queryTag.getKeyword() %></a></td>
						
						<%
						Map<Integer, Map<Integer,Double>> settingRatingMap = new HashMap<Integer, Map<Integer,Double>>();
						for(SearchSetting actualSetting: ContextBasedSearchEvaluation.searchSettings.get(queryTag)){
							//add the old ratings, which are already stored in the database:
							settingRatingMap.put(actualSetting.id, ReadWriteDBUtility.getResourceRatings(idOfParticipant, actualSetting.id));
							
							//only real contexts:
							if(actualSetting.context.contextTypeToConsider != null && !actualSetting.context.contextTypeToConsider.equals(SearchContextType.NONE)){%>
								<td><strong>relevant to context?</strong><br/>
									<strong>context:</strong> <%= actualSetting.context.toHTMLString() %>
								</td>
						<%	}else{// No Query Context -> Evaluation of Relevance to Query without context: 
							idOfSearchSettingWithoutContext = actualSetting.id;
						}
						  } 
						if(idOfSearchSettingWithoutContext == -1){
							//If the NONE-Context Setting was not explicitly put into the setting list for the tag
							//then we create one, because the participants always have to rate also the relevance to
							//the query (without context)
							SearchSetting searchSettingWithoutContext =  new SearchSetting(queryTag, SearchContextFactory.constructEmptyContext());
							idOfSearchSettingWithoutContext = ReadWriteDBUtility.storeIfNotThere(searchSettingWithoutContext);
						}%>
					</tr>
					<% 	//now we list all tags:
					String initialRatingValue = "";
					double theValue = -1.0;
						for(int j = 0; j< resultResources.size(); j++){%>
						<tr>
							<td><a target="previewBrowserWindow" href="<%= resultResources.get(j).getIdentifiable().getURI() %>"><%= resultResources.get(j).getIdentifiable().getLabel() %></a> </td> 
							 
							<td><a href="#" id="iframetest" class="highslide" onclick="return hs.htmlExpand(this, { src: '<%= resultResources.get(j).getIdentifiable().getURI() %>', align: 'center',  objectType: 'iframe',  minWidth: 600, objectLoadTime: 'before', allowWidthReduction: 1})">preview</a> </td>
							
							<td>
								<% ratingCounter++; %>
								<div class="slider-track" id="track<%=ratingCounter %>" style="width:200px; height:9px;">
									<div class="slider-track-left" id="track<%=ratingCounter %>-left"></div>
									<div id="handle<%=ratingCounter %>" style="width:19px; height:20px;"><img src="./images/slider-images-handle.png" alt="" style="float: left;" /></div>
								</div>
								<p id="info<%=ratingCounter %>" style="font-size: x-small; color: gray; font-style: italic;">&nbsp;</p>

								<% 
								if(settingRatingMap.containsKey(idOfSearchSettingWithoutContext) && settingRatingMap.get(idOfSearchSettingWithoutContext).containsKey(Integer.parseInt(resultResources.get(j).getIdentifiable().getId()))){
									theValue = settingRatingMap.get(idOfSearchSettingWithoutContext).get(Integer.parseInt(resultResources.get(j).getIdentifiable().getId()));
									initialRatingValue = "sliderValue: ";
									if(theValue < 1.0){ initialRatingValue += " 0.2, ";}
									else if(theValue < 2.0){ initialRatingValue += " 0.4, ";}
									else if(theValue < 3.0){ initialRatingValue += " 0.6, ";}
									else if(theValue < 4.0){ initialRatingValue += " 0.8, ";}
									else{ initialRatingValue += " 1.0, ";}
								}else {
									initialRatingValue = "";
								}
								%>
								<script type="text/javascript" language="javascript">
								// <![CDATA[
								
									// horizontal slider control
									new Control.Slider('handle<%=ratingCounter %>', 'track<%=ratingCounter %>', {
										values:[0, 0.2, 0.4, 0.6, 0.8, 1.0],
										<%= initialRatingValue %>
										onSlide: function(v) { 
												if(v == 0){$('info<%=ratingCounter %>').innerHTML = "please select..."; }
												else if(v == 0.2){ $('info<%=ratingCounter %>').innerHTML = "I don't know";}
												else if(v == 0.4){ $('info<%=ratingCounter %>').innerHTML = "no"; }
												else if(v == 0.6){ $('info<%=ratingCounter %>').innerHTML = "rather no"; }
												else if(v == 0.8){ $('info<%=ratingCounter %>').innerHTML = "rather yes"; }
												else{ $('info<%=ratingCounter %>').innerHTML = "yes"; }
										   		},
										onChange: function(v) { 
											if(v != 0){
												if(v == 0.2){ $('info<%=ratingCounter %>').innerHTML = "I don't know"; v = 0;}
												else if(v == 0.4){ $('info<%=ratingCounter %>').innerHTML = "no"; v = 1.0;}
												else if(v == 0.6){ $('info<%=ratingCounter %>').innerHTML = "rather no"; v = 2.0;}
												else if(v == 0.8){ $('info<%=ratingCounter %>').innerHTML = "rather yes"; v = 3.0;}
												else{ $('info<%=ratingCounter %>').innerHTML = "yes"; v = 4.0;}
												
										   		storeResourceRating('<%= resultResources.get(j).getIdentifiable().getId() %>', v, <%= idOfSearchSettingWithoutContext %>); }
										   	}
									});
						
								// ]]>
								</script>
								
							<% ratingCounter++; %>
							</td>
							
							<%for(SearchSetting actualSetting: ContextBasedSearchEvaluation.searchSettings.get(queryTag)){
							//only real contexts:
							if(actualSetting.context.contextTypeToConsider != null && !actualSetting.context.contextTypeToConsider.equals(SearchContextType.NONE)){%>
								<td>
								<% ratingCounter++; %>
								<div class="slider-track" id="track<%=ratingCounter %>" style="width:200px; height:9px;">
									<div class="slider-track-left" id="track<%=ratingCounter %>-left"></div>
									<div id="handle<%=ratingCounter %>" style="width:19px; height:20px;"><img src="./images/slider-images-handle.png" alt="" style="float: left;" /></div>
								</div>
								<p id="info<%=ratingCounter %>" style="font-size: x-small; color: gray; font-style: italic;">&nbsp;</p>
								<% 
								if(settingRatingMap.containsKey(actualSetting.id) && settingRatingMap.get(actualSetting.id).containsKey(Integer.parseInt(resultResources.get(j).getIdentifiable().getId()))){
									theValue = settingRatingMap.get(actualSetting.id).get(Integer.parseInt(resultResources.get(j).getIdentifiable().getId()));
									initialRatingValue = "sliderValue: ";
									if(theValue < 1.0){ initialRatingValue += " 0.2, ";}
									else if(theValue < 2.0){ initialRatingValue += " 0.4, ";}
									else if(theValue < 3.0){ initialRatingValue += " 0.6, ";}
									else if(theValue < 4.0){ initialRatingValue += " 0.8, ";}
									else{ initialRatingValue += " 1.0, ";}
								}else {
									initialRatingValue = "";
								}
								%>
								
								<script type="text/javascript" language="javascript">
								// <![CDATA[
								
									// horizontal slider control
									new Control.Slider('handle<%=ratingCounter %>', 'track<%=ratingCounter %>', {
										values:[0, 0.2, 0.4, 0.6, 0.8, 1.0],
										<%= initialRatingValue %>
										onSlide: function(v) { 
												if(v == 0){$('info<%=ratingCounter %>').innerHTML = "please select..."; }
												else if(v == 0.2){ $('info<%=ratingCounter %>').innerHTML = "I don't know";}
												else if(v == 0.4){ $('info<%=ratingCounter %>').innerHTML = "no"; }
												else if(v == 0.6){ $('info<%=ratingCounter %>').innerHTML = "rather no"; }
												else if(v == 0.8){ $('info<%=ratingCounter %>').innerHTML = "rather yes"; }
												else{ $('info<%=ratingCounter %>').innerHTML = "yes"; }
										   		},
										onChange: function(v) { 
											if(v != 0){
												if(v == 0.2){ $('info<%=ratingCounter %>').innerHTML = "I don't know"; v = 0;}
												else if(v == 0.4){ $('info<%=ratingCounter %>').innerHTML = "no"; v = 1.0;}
												else if(v == 0.6){ $('info<%=ratingCounter %>').innerHTML = "rather no"; v = 2.0;}
												else if(v == 0.8){ $('info<%=ratingCounter %>').innerHTML = "rather yes"; v = 3.0;}
												else{ $('info<%=ratingCounter %>').innerHTML = "yes"; v = 4.0;}
												
										   		storeResourceRating('<%= resultResources.get(j).getIdentifiable().getId() %>', v, <%=  actualSetting.id %>); }
										   	}
									});
						
								// ]]>
								</script>
								
							<% ratingCounter++; %>
							</td>
						<%	}
						  } %>
						  
						</tr>
						<%rowCounter++;
							if(rowCounter > 14){
							rowCounter = 0;%>
								<tr>
						<td><strong>resource </strong><span style="font-size: x-small;color: gray;">ordered by label</span></td>
						<td><strong>click to show preview </strong></td>
						<td><strong>relevant to query? </strong><br/>query: <a href="<%= queryTag.getURI() %>" target="previewBrowserWindow"><%= queryTag.getKeyword() %></a></td>
						
						<%
						for(SearchSetting actualSetting: ContextBasedSearchEvaluation.searchSettings.get(queryTag)){
							//only real contexts:
							if(actualSetting.context.contextTypeToConsider != null && !actualSetting.context.contextTypeToConsider.equals(SearchContextType.NONE)){%>
								<td><strong>relevant to context?</strong><br/>
									<strong>context:</strong> <%= actualSetting.context.toHTMLString() %>
								</td>
						<%	}else{// No Query Context -> Evaluation of Relevance to Query without context: 
							idOfSearchSettingWithoutContext = actualSetting.id;
						}
						  } 
						if(idOfSearchSettingWithoutContext == -1){
							//If the NONE-Context Setting was not explicitly put into the setting list for the tag
							//then we create one, because the participants always have to rate also the relevance to
							//the query (without context)
							SearchSetting searchSettingWithoutContext =  new SearchSetting(queryTag, SearchContextFactory.constructEmptyContext());
							idOfSearchSettingWithoutContext = ReadWriteDBUtility.storeIfNotThere(searchSettingWithoutContext);
						}%>
					</tr>
							<%}
						}//end of result ranking FOR%>
					</table>
					<br/><br/>
				
				<!-- TAG -->
				
				<br/><br/>
				<h2>Tags:</h2>
				<br/><br/>
				
				<% 
				List<WeightedTag> resultTags = ContextBasedSearchEvaluation.getAccumulatedTagList(queryTag);
				rowCounter=0;
				   %>					
					<table style="border: thin; border-style: solid; border-color: gray;">
					<tr>
						<td><strong>tag </strong><span style="font-size: x-small;color: gray;">ordered by label</span></td>
						<td><strong>click to show preview </strong></td>
						<td><strong>relevant to query? </strong><br/>query: <a href="<%= queryTag.getURI() %>" target="previewBrowserWindow"><%= queryTag.getKeyword() %></a></td>
						
						<%
						settingRatingMap = new HashMap<Integer, Map<Integer,Double>>();
						for(SearchSetting actualSetting: ContextBasedSearchEvaluation.searchSettings.get(queryTag)){
							//add the old ratings, which are already stored in the database:
							settingRatingMap.put(actualSetting.id, ReadWriteDBUtility.getTagRatings(idOfParticipant, actualSetting.id));
							
							//only real contexts:
							if(actualSetting.context.contextTypeToConsider != null && !actualSetting.context.contextTypeToConsider.equals(SearchContextType.NONE)){%>
								<td><strong>relevant to context?</strong><br/>
									<strong>context:</strong> <%= actualSetting.context.toHTMLString() %>
								</td>
						<%	}
						  } 
						%>
					</tr>
					<% 	//now we list all tags:
					initialRatingValue = "";
					theValue = -1.0;
						for(int j = 0; j< resultTags.size(); j++){%>
						<tr>
							<td><a target="previewBrowserWindow" href="<%= resultTags.get(j).getIdentifiable().getURI() %>"><%= resultTags.get(j).getIdentifiable().getLabel() %></a> </td> 
							 
							<td><a href="#" id="iframetest" class="highslide" onclick="return hs.htmlExpand(this, { src: '<%= resultTags.get(j).getIdentifiable().getURI() %>', align: 'center',  objectType: 'iframe',  minWidth: 600, objectLoadTime: 'before', allowWidthReduction: 1})">preview</a> </td>
							
							<td>
								<% ratingCounter++; %>
								<div class="slider-track" id="track<%=ratingCounter %>" style="width:200px; height:9px;">
									<div class="slider-track-left" id="track<%=ratingCounter %>-left"></div>
									<div id="handle<%=ratingCounter %>" style="width:19px; height:20px;"><img src="./images/slider-images-handle.png" alt="" style="float: left;" /></div>
								</div>
								<p id="info<%=ratingCounter %>" style="font-size: x-small; color: gray; font-style: italic;">&nbsp;</p>

								<% 
								if(settingRatingMap.containsKey(idOfSearchSettingWithoutContext) && settingRatingMap.get(idOfSearchSettingWithoutContext).containsKey(Integer.parseInt(resultTags.get(j).getIdentifiable().getId()))){
									theValue = settingRatingMap.get(idOfSearchSettingWithoutContext).get(Integer.parseInt(resultTags.get(j).getIdentifiable().getId()));
									initialRatingValue = "sliderValue: ";
									if(theValue < 1.0){ initialRatingValue += " 0.2, ";}
									else if(theValue < 2.0){ initialRatingValue += " 0.4, ";}
									else if(theValue < 3.0){ initialRatingValue += " 0.6, ";}
									else if(theValue < 4.0){ initialRatingValue += " 0.8, ";}
									else{ initialRatingValue += " 1.0, ";}
								}else {
									initialRatingValue = "";
								}
								%>
								<script type="text/javascript" language="javascript">
								// <![CDATA[
								
									// horizontal slider control
									new Control.Slider('handle<%=ratingCounter %>', 'track<%=ratingCounter %>', {
										values:[0, 0.2, 0.4, 0.6, 0.8, 1.0],
										<%= initialRatingValue %>
										onSlide: function(v) { 
												if(v == 0){$('info<%=ratingCounter %>').innerHTML = "please select..."; }
												else if(v == 0.2){ $('info<%=ratingCounter %>').innerHTML = "I don't know";}
												else if(v == 0.4){ $('info<%=ratingCounter %>').innerHTML = "no"; }
												else if(v == 0.6){ $('info<%=ratingCounter %>').innerHTML = "rather no"; }
												else if(v == 0.8){ $('info<%=ratingCounter %>').innerHTML = "rather yes"; }
												else{ $('info<%=ratingCounter %>').innerHTML = "yes"; }
										   		},
										onChange: function(v) { 
											if(v != 0){
												if(v == 0.2){ $('info<%=ratingCounter %>').innerHTML = "I don't know"; v = 0;}
												else if(v == 0.4){ $('info<%=ratingCounter %>').innerHTML = "no"; v = 1.0;}
												else if(v == 0.6){ $('info<%=ratingCounter %>').innerHTML = "rather no"; v = 2.0;}
												else if(v == 0.8){ $('info<%=ratingCounter %>').innerHTML = "rather yes"; v = 3.0;}
												else{ $('info<%=ratingCounter %>').innerHTML = "yes"; v = 4.0;}
												
										   		storeTagRating('<%= resultTags.get(j).getIdentifiable().getId() %>', v, <%= idOfSearchSettingWithoutContext %>); }
										   	}
									});
						
								// ]]>
								</script>
								
							<% ratingCounter++; %>
							</td>
							
							<%for(SearchSetting actualSetting: ContextBasedSearchEvaluation.searchSettings.get(queryTag)){
							//only real contexts:
							if(actualSetting.context.contextTypeToConsider != null && !actualSetting.context.contextTypeToConsider.equals(SearchContextType.NONE)){%>
								<td>
								<% ratingCounter++; %>
								<div class="slider-track" id="track<%=ratingCounter %>" style="width:200px; height:9px;">
									<div class="slider-track-left" id="track<%=ratingCounter %>-left"></div>
									<div id="handle<%=ratingCounter %>" style="width:19px; height:20px;"><img src="./images/slider-images-handle.png" alt="" style="float: left;" /></div>
								</div>
								<p id="info<%=ratingCounter %>" style="font-size: x-small; color: gray; font-style: italic;">&nbsp;</p>
								<% 
								if(settingRatingMap.containsKey(actualSetting.id) && settingRatingMap.get(actualSetting.id).containsKey(Integer.parseInt(resultTags.get(j).getIdentifiable().getId()))){
									theValue = settingRatingMap.get(actualSetting.id).get(Integer.parseInt(resultTags.get(j).getIdentifiable().getId()));
									initialRatingValue = "sliderValue: ";
									if(theValue < 1.0){ initialRatingValue += " 0.2, ";}
									else if(theValue < 2.0){ initialRatingValue += " 0.4, ";}
									else if(theValue < 3.0){ initialRatingValue += " 0.6, ";}
									else if(theValue < 4.0){ initialRatingValue += " 0.8, ";}
									else{ initialRatingValue += " 1.0, ";}
								}else {
									initialRatingValue = "";
								}
								%>
								
								<script type="text/javascript" language="javascript">
								// <![CDATA[
								
									// horizontal slider control
									new Control.Slider('handle<%=ratingCounter %>', 'track<%=ratingCounter %>', {
										values:[0, 0.2, 0.4, 0.6, 0.8, 1.0],
										<%= initialRatingValue %>
										onSlide: function(v) { 
												if(v == 0){$('info<%=ratingCounter %>').innerHTML = "please select..."; }
												else if(v == 0.2){ $('info<%=ratingCounter %>').innerHTML = "I don't know";}
												else if(v == 0.4){ $('info<%=ratingCounter %>').innerHTML = "no"; }
												else if(v == 0.6){ $('info<%=ratingCounter %>').innerHTML = "rather no"; }
												else if(v == 0.8){ $('info<%=ratingCounter %>').innerHTML = "rather yes"; }
												else{ $('info<%=ratingCounter %>').innerHTML = "yes"; }
										   		},
										onChange: function(v) { 
											if(v != 0){
												if(v == 0.2){ $('info<%=ratingCounter %>').innerHTML = "I don't know"; v = 0;}
												else if(v == 0.4){ $('info<%=ratingCounter %>').innerHTML = "no"; v = 1.0;}
												else if(v == 0.6){ $('info<%=ratingCounter %>').innerHTML = "rather no"; v = 2.0;}
												else if(v == 0.8){ $('info<%=ratingCounter %>').innerHTML = "rather yes"; v = 3.0;}
												else{ $('info<%=ratingCounter %>').innerHTML = "yes"; v = 4.0;}
												
										   		storeTagRating('<%= resultTags.get(j).getIdentifiable().getId() %>', v, <%=  actualSetting.id %>); }
										   	}
									});
						
								// ]]>
								</script>
								
							<% ratingCounter++; %>
							</td>
						<%	}
						  } %>
						  
						</tr>
						<%rowCounter++;
							if(rowCounter > 14){
							rowCounter = 0;%>
								<tr>
						<td><strong>tag </strong><span style="font-size: x-small;color: gray;">ordered by label</span></td>
						<td><strong>click to show preview </strong></td>
						<td><strong>relevant to query? </strong><br/>query: <a href="<%= queryTag.getURI() %>" target="previewBrowserWindow"><%= queryTag.getKeyword() %></a></td>
						
						<%
						for(SearchSetting actualSetting: ContextBasedSearchEvaluation.searchSettings.get(queryTag)){
							//only real contexts:
							if(actualSetting.context.contextTypeToConsider != null && !actualSetting.context.contextTypeToConsider.equals(SearchContextType.NONE)){%>
								<td><strong>relevant to context?</strong><br/>
									<strong>context:</strong> <%= actualSetting.context.toHTMLString() %>
								</td>
						<%	}
						  } 
						%>
					</tr>
							<%}
						}//end of result ranking FOR%>
					</table>
					<br/><br/>
				
				
				<h3>Users:</h3>
				<br/><br/>
				<!-- USER -->
				<% List<WeightedUser> result = ContextBasedSearchEvaluation.getAccumulatedUserList(queryTag); 
				   //int idOfSearchSettingWithoutContext = -1;%>					
					<table style="border: thin; border-style: solid; border-color: gray;">
					<tr>
						<td><strong>user </strong><span style="font-size: x-small;color: gray;">ordered by label</span></td>
						<td><strong>click to show preview </strong></td>
						<td><strong>relevant to query? </strong><br/>query: <a href="<%= queryTag.getURI() %>" target="previewBrowserWindow"><%= queryTag.getKeyword() %></a></td>
						
						<%
						settingRatingMap = new HashMap<Integer, Map<Integer,Double>>();
						for(SearchSetting actualSetting: ContextBasedSearchEvaluation.searchSettings.get(queryTag)){
							//add the old ratings, which are already stored in the database:
							settingRatingMap.put(actualSetting.id, ReadWriteDBUtility.getUserRatings(idOfParticipant, actualSetting.id));
							
							//only real contexts:
							if(actualSetting.context.contextTypeToConsider != null && !actualSetting.context.contextTypeToConsider.equals(SearchContextType.NONE)){%>
								<td><strong>relevant to context?</strong><br/>
									<strong>context:</strong> <%= actualSetting.context.toHTMLString() %>
								</td>
						<%	}else{// No Query Context -> Evaluation of Relevance to Query without context: 
							idOfSearchSettingWithoutContext = actualSetting.id;
						}
						  } 
						if(idOfSearchSettingWithoutContext == -1){
							//If the NONE-Context Setting was not explicitly put into the setting list for the tag
							//then we create one, because the participants always have to rate also the relevance to
							//the query (without context)
							SearchSetting searchSettingWithoutContext =  new SearchSetting(queryTag, SearchContextFactory.constructEmptyContext());
							idOfSearchSettingWithoutContext = ReadWriteDBUtility.storeIfNotThere(searchSettingWithoutContext);
						}%>
					</tr>
					<% 	//now we list all users:
						initialRatingValue = "";
					theValue = -1.0;
						for(int j = 0; j< result.size(); j++){%>
						<tr>
							<td><a target="previewBrowserWindow" href="<%= result.get(j).getIdentifiable().getURI() %>"><%= result.get(j).getIdentifiable().getLabel() %></a> </td> 
							 
							<td><a href="#" id="iframetest" class="highslide" onclick="return hs.htmlExpand(this, { src: '<%= result.get(j).getIdentifiable().getURI() %>', align: 'center',  objectType: 'iframe',  minWidth: 600, objectLoadTime: 'before', allowWidthReduction: 1})">preview</a> </td>
							
							<td>
								<% ratingCounter++; %>
								<div class="slider-track" id="track<%=ratingCounter %>" style="width:200px; height:9px;">
									<div class="slider-track-left" id="track<%=ratingCounter %>-left"></div>
									<div id="handle<%=ratingCounter %>" style="width:19px; height:20px;"><img src="./images/slider-images-handle.png" alt="" style="float: left;" /></div>
								</div>
								<p id="info<%=ratingCounter %>" style="font-size: x-small; color: gray; font-style: italic;">&nbsp;</p>

								<% 
								if(settingRatingMap.containsKey(idOfSearchSettingWithoutContext) && settingRatingMap.get(idOfSearchSettingWithoutContext).containsKey(Integer.parseInt(result.get(j).getIdentifiable().getId()))){
									theValue = settingRatingMap.get(idOfSearchSettingWithoutContext).get(Integer.parseInt(result.get(j).getIdentifiable().getId()));
									initialRatingValue = "sliderValue: ";
									if(theValue < 1.0){ initialRatingValue += " 0.2, ";}
									else if(theValue < 2.0){ initialRatingValue += " 0.4, ";}
									else if(theValue < 3.0){ initialRatingValue += " 0.6, ";}
									else if(theValue < 4.0){ initialRatingValue += " 0.8, ";}
									else{ initialRatingValue += " 1.0, ";}
								}else {
									initialRatingValue = "";
								}
								%>
								<script type="text/javascript" language="javascript">
								// <![CDATA[
								
									// horizontal slider control
									new Control.Slider('handle<%=ratingCounter %>', 'track<%=ratingCounter %>', {
										values:[0, 0.2, 0.4, 0.6, 0.8, 1.0],
										<%= initialRatingValue %>
										onSlide: function(v) { 
												if(v == 0){$('info<%=ratingCounter %>').innerHTML = "please select..."; }
												else if(v == 0.2){ $('info<%=ratingCounter %>').innerHTML = "I don't know";}
												else if(v == 0.4){ $('info<%=ratingCounter %>').innerHTML = "no"; }
												else if(v == 0.6){ $('info<%=ratingCounter %>').innerHTML = "rather no"; }
												else if(v == 0.8){ $('info<%=ratingCounter %>').innerHTML = "rather yes"; }
												else{ $('info<%=ratingCounter %>').innerHTML = "yes"; }
										   		},
										onChange: function(v) { 
											if(v != 0){
												if(v == 0.2){ $('info<%=ratingCounter %>').innerHTML = "I don't know"; v = 0;}
												else if(v == 0.4){ $('info<%=ratingCounter %>').innerHTML = "no"; v = 1.0;}
												else if(v == 0.6){ $('info<%=ratingCounter %>').innerHTML = "rather no"; v = 2.0;}
												else if(v == 0.8){ $('info<%=ratingCounter %>').innerHTML = "rather yes"; v = 3.0;}
												else{ $('info<%=ratingCounter %>').innerHTML = "yes"; v = 4.0;}
												
										   		storeUserRating('<%= result.get(j).getIdentifiable().getId() %>', v, <%= idOfSearchSettingWithoutContext %>); }
										   	}
									});
						
								// ]]>
								</script>
								
							<% ratingCounter++; %>
							</td>
							
							<%for(SearchSetting actualSetting: ContextBasedSearchEvaluation.searchSettings.get(queryTag)){
							//only real contexts:
							if(actualSetting.context.contextTypeToConsider != null && !actualSetting.context.contextTypeToConsider.equals(SearchContextType.NONE)){%>
								<td>
								<% ratingCounter++; %>
								<div class="slider-track" id="track<%=ratingCounter %>" style="width:200px; height:9px;">
									<div class="slider-track-left" id="track<%=ratingCounter %>-left"></div>
									<div id="handle<%=ratingCounter %>" style="width:19px; height:20px;"><img src="./images/slider-images-handle.png" alt="" style="float: left;" /></div>
								</div>
								<p id="info<%=ratingCounter %>" style="font-size: x-small; color: gray; font-style: italic;">&nbsp;</p>
								<% 
								if(settingRatingMap.containsKey(actualSetting.id) && settingRatingMap.get(actualSetting.id).containsKey(Integer.parseInt(result.get(j).getIdentifiable().getId()))){
									theValue = settingRatingMap.get(actualSetting.id).get(Integer.parseInt(result.get(j).getIdentifiable().getId()));
									initialRatingValue = "sliderValue: ";
									if(theValue < 1.0){ initialRatingValue += " 0.2, ";}
									else if(theValue < 2.0){ initialRatingValue += " 0.4, ";}
									else if(theValue < 3.0){ initialRatingValue += " 0.6, ";}
									else if(theValue < 4.0){ initialRatingValue += " 0.8, ";}
									else{ initialRatingValue += " 1.0, ";}
								}else {
									initialRatingValue = "";
								}
								%>
								
								<script type="text/javascript" language="javascript">
								// <![CDATA[
								
									// horizontal slider control
									new Control.Slider('handle<%=ratingCounter %>', 'track<%=ratingCounter %>', {
										values:[0, 0.2, 0.4, 0.6, 0.8, 1.0],
										<%= initialRatingValue %>
										onSlide: function(v) { 
												if(v == 0){$('info<%=ratingCounter %>').innerHTML = "please select..."; }
												else if(v == 0.2){ $('info<%=ratingCounter %>').innerHTML = "I don't know";}
												else if(v == 0.4){ $('info<%=ratingCounter %>').innerHTML = "no"; }
												else if(v == 0.6){ $('info<%=ratingCounter %>').innerHTML = "rather no"; }
												else if(v == 0.8){ $('info<%=ratingCounter %>').innerHTML = "rather yes"; }
												else{ $('info<%=ratingCounter %>').innerHTML = "yes"; }
										   		},
										onChange: function(v) { 
											if(v != 0){
												if(v == 0.2){ $('info<%=ratingCounter %>').innerHTML = "I don't know"; v = 0;}
												else if(v == 0.4){ $('info<%=ratingCounter %>').innerHTML = "no"; v = 1.0;}
												else if(v == 0.6){ $('info<%=ratingCounter %>').innerHTML = "rather no"; v = 2.0;}
												else if(v == 0.8){ $('info<%=ratingCounter %>').innerHTML = "rather yes"; v = 3.0;}
												else{ $('info<%=ratingCounter %>').innerHTML = "yes"; v = 4.0;}
												
										   		storeUserRating('<%= result.get(j).getIdentifiable().getId() %>', v, <%=  actualSetting.id %>); }
										   	}
									});
						
								// ]]>
								</script>
								
							<% ratingCounter++; %>
							</td>
						<%	}
						  } %>
						  
						</tr>
						<%rowCounter++;
							if(rowCounter > 14){
							rowCounter = 0;%>
								<tr>
						<td><strong>user</strong><span style="font-size: x-small;color: gray;">ordered by label</span></td>
						<td><strong>click to show preview </strong></td>
						<td><strong>relevant to query? </strong><br/>query: <a href="<%= queryTag.getURI() %>" target="previewBrowserWindow"><%= queryTag.getKeyword() %></a></td>
						
						<%
						for(SearchSetting actualSetting: ContextBasedSearchEvaluation.searchSettings.get(queryTag)){
							//only real contexts:
							if(actualSetting.context.contextTypeToConsider != null && !actualSetting.context.contextTypeToConsider.equals(SearchContextType.NONE)){%>
								<td><strong>relevant to context?</strong><br/>
									<strong>context:</strong> <%= actualSetting.context.toHTMLString() %>
								</td>
						<%	}else{// No Query Context -> Evaluation of Relevance to Query without context: 
							idOfSearchSettingWithoutContext = actualSetting.id;
						}
						  } 
						if(idOfSearchSettingWithoutContext == -1){
							//If the NONE-Context Setting was not explicitly put into the setting list for the tag
							//then we create one, because the participants always have to rate also the relevance to
							//the query (without context)
							SearchSetting searchSettingWithoutContext =  new SearchSetting(queryTag, SearchContextFactory.constructEmptyContext());
							idOfSearchSettingWithoutContext = ReadWriteDBUtility.storeIfNotThere(searchSettingWithoutContext);
						}%>
					</tr>
							<%}
						}//end of result ranking FOR%>
						
						
					</table>
					<br/><br/>					
					
					
					
					
				
					<p style="font-size: medium"><strong>Thank you!<br />
					<br/>
	
					
				<%//} //end of queryTag FOR%>
		<% } %>
		</div>
		<div id="sidebar_right">
			
		</div>
	</div>
	<div id="footer">
		<%@ include file="../jsp-includes/footer.jsp" %>
	</div>
</body>
</html>